﻿using System;
using System.Windows;
using _3DTicTacToe.Net;

namespace _3DTicTacToe.UI
{
    partial class NetHostPropertiesWindow : Window
    {
        private bool _showStartWindow = true;

        public NetHostPropertiesWindow()
        {
            InitializeComponent();

            playerControl.PlayerPropsChanged += PlayerChanged;
        }

        void PlayerChanged(bool valid)
        {
            continueButton.IsEnabled = valid;
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void continueButton_Click(object sender, RoutedEventArgs e)
        {
            _showStartWindow = false;

            var connection = Connection.CreateServer(int.Parse(portTextBox.Text));
            connection.Start();

            new NetLobbyWindow(connection, playerControl.Player).Show();
            Close();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (_showStartWindow)
                new StartWindow().Show();
        }
    }
}
